package fr.mairie.parc.control.user;

import javax.annotation.Resource;

import org.apache.click.control.FieldSet;
import org.apache.click.control.Form;
import org.apache.click.control.Select;
import org.apache.click.control.TextField;
import org.apache.click.extras.control.IntegerField;

import fr.mairie.parc.domain.User;
import fr.mairie.parc.service.UserManager;

public class UserFields {
	
	@Resource protected UserManager userManager ;
	private FieldSet fieldset = new FieldSet("userFieldset", "User");
	private IntegerField idUser = new IntegerField("idUser", "ID", true);
	private TextField nom = new TextField("nom", "Nom",true);
	private TextField prenom = new TextField("prenom", "Prenom",true);
	private Select direction = new Select ("direction", "Direction",true);
	private Select service = new Select ("service", "Service",true);
	private Select batiment = new Select ("batiment", "Batiment",true);
	private TextField etage = new TextField("etage", "Etage",true);	
	private TextField bureau = new TextField("bureau", "Bureau",true);
	
	

	
	
	public UserFields(){
		
		fieldset.add(nom);
		fieldset.add(prenom);
		/*direction.setDefaultOption(new Option("direction", "Choisir une direction"));
		direction.add(new DataProvider() {
			@SuppressWarnings("unchecked")
			public List getData() {
				
				List <String> listDirection = userManager.selectDirection();
                List optionList = new ArrayList<String>();

                for (String dir : listDirection) {
                        optionList.add(new Option(""+dir,""+dir));
                }
                return optionList;
            }
        });*/
		fieldset.add(direction);
		/*service.setDefaultOption(new Option("service", "Choisir un service"));
		service.add(new DataProvider() {
			@SuppressWarnings("unchecked")
			public List getData(){
				List optionList = new ArrayList();
				optionList.add(userManager.selectService());
				return optionList;
			}
			
		});*/
		fieldset.add(service);
		/*batiment.setDefaultOption(new Option("service", "Choisir un service"));
		batiment.add(new DataProvider() {
			public List getData(){
				List optionList = userManager.selectBatiment();
				return optionList;
			}
			
		});*/
		fieldset.add(batiment);
		fieldset.add(etage);
		fieldset.add(bureau);
		
		
		
		
	}
	
	public void addAll(Form form) {
		form.add(fieldset);		
	}

	public void setFieldsValues(User user) {
		//idUser.setInteger(user.getIdUser());
		nom.setValue(user.getNom());
		prenom.setValue(user.getPrenom());
		direction.setValue(user.getDirection());
		service.setValue(user.getService());
		batiment.setValue(user.getBatiment());
		etage.setValue(user.getEtage());
		bureau.setValue(user.getBureau());
		
		
	}
	
	public void getFieldsValues(User in) {
		//in.setIdUser(idUser.getInteger());
		in.setNom(nom.getValue());
		in.setPrenom(prenom.getValue());
		in.setDirection(direction.getValue());
		in.setService(service.getValue());
		in.setBatiment(batiment.getValue());
		in.setEtage(etage.getValue());
		in.setBureau(bureau.getValue());
		
		
	}
		
	public void setReadonly(boolean disabled) {
		fieldset.setReadonly(disabled);
	}

	public void setIdUser(User src) {
		idUser.setInteger(src.getIdUser());
	}

	public Integer getIdUser() {
		return idUser.getInteger();
	}

	

	

}

